package com.lehezn.opensource.appkit.ControlModule;

import com.github.mikephil.charting.data.Entry;
import com.lehezn.opensource.appkit.R;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by es-ll on 17/10/5.
 */

public class MeterInfo {


    public byte[] addr;
    public String addrStr;
    public byte online;//在线状态
    public byte successPercent;//抄读成功率
    public byte error;//故障


    public byte type;//类型

    public byte baud;//波特率
    /**
     * 奇偶
     */
    public byte parity;//
    public boolean isSanxiang;//是否三相
    public boolean isPeakvall;//是否支持峰谷
    public String name;//表名称

    public byte channel;

    public String vol = "0.0";//电压
    public String cur = "0.0";//电流
    public String power = "0.0";//有功功率
    public String powerFactory = "0.0";//功率因数


    public double enery;//正向有功电量
    public double enery0;//正向有功电量 尖
    public double enery1;//正向有功电量 峰
    public double enery2;//正向有功电量 平
    public double enery3;//正向有功电量 谷


    public double[] freezeDay = new double[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//日冻结数据
    public double[] freezeMonth = new double[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//月冻结数据

    public byte reportTime;

    /**
     * 本月电量,当前电量示数-上月冻结电量
     *
     * @return
     */
    public double getCurMonthEnery() {

        double curMonthEnery = freezeMonth[0];

        return curMonthEnery;
    }

    /**
     * 本日电量，当前电量示数-昨日冻结电量
     *
     * @return
     */
    public double getCurDayEnery() {
        double cutDayEnery = freezeDay[0];
        return cutDayEnery;
    }

    public int getIcon() {
        int resId = R.drawable.e;
        switch (type) {
            case Util.TYPE_WATER:
                resId = R.drawable.w;
                break;
            case Util.TYPE_GOS:
                resId = R.drawable.g;
                break;
            case Util.TYPE_HEAT:
                resId = R.drawable.h;
                break;
            case Util.TYPE_SINGLE_METER:
                resId = R.drawable.e;
                break;
            case Util.TYPE_MUTIL_METER:
                resId = R.drawable.e;
                break;

        }

        return resId;
    }


    public ArrayList<Entry> getDayFreeze(int dayCount) {
        ArrayList<Entry> entries = new ArrayList<Entry>();
        for (int i = dayCount - 1; i >= 0; i--) {
            if (i >= freezeDay.length) {
                MyLog.d("getDayFreeze-->" + Arrays.toString(freezeDay));
                return entries;
            }
            float y = (float) this.freezeDay[i];
            // turn your data into Entry objects
            Entry entry=new Entry(dayCount-1-i, y);
            entries.add(entry);
            MyLog.d("getDayFreeze-->" +entry.toString());

        }
        return entries;
    }

    public ArrayList<Entry> getMonthFreeze() {
        ArrayList<Entry> entries = new ArrayList<Entry>();
        for (int i = 11; i >= 0; i--) {
            if (i >= freezeMonth.length) {
                MyLog.d("getMonthFreeze-->" + Arrays.toString(freezeMonth));
                return entries;
            }
            float y = (float) this.freezeMonth[i];
            // turn your data into Entry objects
            Entry entry=new Entry(11-i, y);
            entries.add(entry);
            MyLog.d("getMonthFreeze-->" +entry.toString());
        }
        return entries;
    }

//    private double getAllMoney(double price){
//        double result=0;
//        if (type==Util.TYPE_SINGLE_METER||type==Util.TYPE_MUTIL_METER){
//            result=
//        }
//        return  result;
//
//    }

    public String toString() {
        return "addrstr=" + addrStr + " name=" + name + " type=" + type + " channel=" + channel + "buard=" + baud
                + " enery=" + enery + " enery0=" + enery0 + " enery1=" + enery1 + " enery2=" + enery2 + " enery3=" + enery3
                + " 电压=" + vol + " 电流=" + cur + "";
    }

}
